package com.kfm.servlet;

import com.kfm.util.CaptchaUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/captcha")
public class CaptchaServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置位数
//        CaptchaUtil.out(5, request, response);
        // 设置宽、高、位数
//        CaptchaUtil.out(100, 48, 5, request, response);
//
//        // 使用gif验证码
//        GifCaptcha gifCaptcha = new GifCaptcha(130,48,4);
//        CaptchaUtil.out(gifCaptcha, request, response);

        // 算术
//        ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48);
//        captcha.setLen(3);  // 几位数运算，默认是两位
//        captcha.getArithmeticString();  // 获取运算的公式：3+2=?
//        System.out.println(captcha.text());  // 获取运算的结果：5
//
//        captcha.out(response.getOutputStream());  // 输出验证码

        try {
            new CaptchaUtil().getRandcode(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
